﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Interface.SheepFileModelInterface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.SheepfilemodelCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.SheepfilemodelCommandHandler
{
    public class SheepfilemodelsAddCommandHandler :IRequestHandler<SheepfilemodelsAddCommand, Results<int>>
    {
        private readonly ISheepFileModelService _sheepFileModelService;
        public SheepfilemodelsAddCommandHandler(ISheepFileModelService sheepFileModelService)
        {
            _sheepFileModelService = sheepFileModelService;
        }
        public async Task<Results<int>> Handle(SheepfilemodelsAddCommand request, CancellationToken cancellationToken)
        {
            var newModel = new Sheepfilemodel
            {
                EarTag = request.EarTag,
                Variety = request.Variety,
                SheepSex = request.SheepSex,
                ElectEarNum = request.ElectEarNum,
                GeneticGrade = request.GeneticGrade,
                PrantEarNum = request.PrantEarNum,
                MatherEarNum = request.MatherEarNum,
                BirthDate = request.BirthDate,
                BirthState = request.BirthState,
                AdmissionDate = request.AdmissionDate,
                BirthPlace = request.BirthPlace,
                BirthWeight = request.BirthWeight,
                BirthContent = request.BirthContent,
                SheepType = request.SheepType,
                
            };
            int affectedRows = await _sheepFileModelService.AddSheepfilemodel(newModel);
            return Results<int>.DataResult(affectedRows);

        }
    }
}
